<!DOCTYPE html>
<html>
<head>
    <title>My Application</title>
    <link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css">
    <link rel="STYLESHEET" type="text/css" href="codebase/css/common/common.css">
    <script src="codebase/dhtmlx.js" type="text/javascript"></script>
    <script>
		var docLayout,mygrid,toolbar;
		
		
        function buildInterface(){
		
			docLayout = new dhtmlXLayoutObject(document.body, "2E");
			docLayout.cells('a').hideHeader();
			docLayout.cells('b').setText("上传");
			
			docLayout.attachEvent("onExpand", function(itemId){
				if (itemId == 'b')
					docLayout.cells("b").attachURL("/fileCenter/file/showUploadForm.do");
			});
		    docLayout.attachEvent("onCollapse", function(itemId){
		    	if (itemId == 'b')
		    		docLayout.cells("b").attachURL("/fileCenter/blank.htm");
		    });
		
		
			docLayout.cells('b').collapse();
			
			loadToolbar();
			loadGrid();
        }
        
		
		function loadToolbar(){
			toolbar = docLayout.cells('a').attachToolbar();
			//toolbar = new dhtmlXToolbarObject("toolbarObj");
			
			toolbar.setIconsPath("codebase/imgs/toolbar/");
			toolbar.addText("info", 1, "选择操作：");
			toolbar.addButton("browse", 2, "浏览文件", "file_open.gif", "file_open.gif");
			toolbar.addSeparator("sep3", 3);
			toolbar.addButton("upload", 4, "上传文件", "file_upload.gif", "file_upload_dis.gif");
			toolbar.addButton("download", 5, "下载文件", "file_download.gif", "file_download_dis.gif");
			toolbar.addButton("delete", 6, "删除文件", "file_remove.gif", "file_remove_dis.gif");
			toolbar.addSeparator("sep3", 7);
			toolbar.addButton("share", 8, "组内共享", "file_share.gif", "file_share_dis.gif");
			toolbar.addButton("review", 9, "提交审核", "file_audit.gif", "file_audit_dis.gif");
			
			toolbar.attachEvent("onClick", function(id) {
		      	if (id == "upload") {
		      		showUpdatePage();
		      	} else if (id == "download") {
		      		doDownload();
		      	} else if (id == "delete") {
		      		doDelete();
		      	} else if (id == "review") {
		      		doReview();
		      	}
		    });
		}
		
		function showUpdatePage() {
			docLayout.cells('b').expand();
		}
		
		function doDownload() {
			var fid = mygrid.getSelectedId();
			if (!fid)
            	return alert("请选择文件，再操作!");
            window.open("/fileCenter/file/download.do?fid=" + fid);
		}
		
		function doReview() {
			var fid = mygrid.getSelectedId();
			if (!fid)
            	return alert("请选择文件，再操作!");
            dhtmlxAjax.get("/fileCenter/review/submitReview.do?fid=" + fid, function(loader){
            	var data = loader.xmlDoc.responseText;
            	eval("var rst = " + data);
            	alert(rst.msg);
            });
		}
		
		function doDelete() {
			var fid = mygrid.getSelectedId();
			if (!fid)
            	return alert("请选择文件，再操作!");
            dhtmlxAjax.get("/fileCenter/file/delete.do?fid=" + fid, function(loader){
            	var data = loader.xmlDoc.responseText;
            	eval("var rst = " + data);
            	if (rst.status) {
            		mygrid.deleteRow(fid);
            	} else {
            		alert(rst.msg);
            	}
            });
		}
		
		function loadGrid(){
			mygrid = docLayout.cells('a').attachGrid();
			mygrid.setImagePath("codebase/imgs/");
			mygrid.setHeader(",文件名,文件后缀,文件尺寸,上传时间");
			mygrid.setInitWidths("50,300,60,100,120");
			mygrid.setColAlign("center,left,left,right,center");
			mygrid.setColTypes("img,ro,ro,ro,ro");
			mygrid.setColSorting("str,str,str,int,str");
			mygrid.setSkin("dhx_skyblue");
			mygrid.init();
			mygrid.loadXML("/fileCenter/file/listFile.do");
		}
		
	
        dhtmlxEvent(window,"load", buildInterface);
    </script>
</head>
<body>
</body>
</html>